package com.lidong.framework.util;


public class StringUtil {
	/**
	 * 判断字符串是空，包括null、""
	 * @param str
	 * @return
	 */
	public static boolean isBlank(String str) {
		return (null == str || str.length() < 1);
	}

	/**
	 * 判断字符串不是空，包括null、""
	 * @param str
	 * @return
	 */
	public static boolean isNotBlank(String str) {
		return !isBlank(str);
	}
	
	public static final String[] fbsArr={"\\","'","\"","\n","\r","\t","<",">"};
	
	public static String dealString4JSON(String keyword) {  
		if (StringUtil.isBlank(keyword)) {  
			 return keyword;  
		}
	    for (String key : fbsArr) {  
            if (keyword.contains(key)) {  
                keyword = keyword.replace(key, "\\" + key);  
            }  
	    }
	    return keyword;  
	}  
	
	/**
	 * 格式化json串，key，value都加上双引号
	 * @param str
	 * @return
	 */
	public static String formatJsonString(String str){
		if(isNotBlank(str)){
			str = str.replaceAll("\\{", "\\{\"");
			str = str.replaceAll(":", "\":\"");
			str = str.replaceAll(",", "\",\"");
			str = str.replaceAll("\\}", "\"\\}");
		}
		return str;
	}
	/**
	 * 比较两个字符串是否相等
	 * @param str1
	 * @param str2
	 * @return
	 */
	public static boolean equals(String str1, String str2){
		return (str1 == null && str2 == null) || (str1 != null && str1.equals(str2));
	}
}
